<?php
// +----------------------------------------------------------------------
// | @filename MenuController.php
// +----------------------------------------------------------------------
// | @author 落花轻舞问君愁 <mwcx1990@qq.com>
// +----------------------------------------------------------------------
// | @datetime 2021-11-01 17:54:56
// +----------------------------------------------------------------------
// | @Description
// +----------------------------------------------------------------------

namespace Addons\Backend\Http\Controllers;

use Addons\Backend\Http\Requests\Menu\CreateMenuRequest;
use Addons\Backend\Http\Requests\Menu\UpdateMenuRequest;
use Addons\Backend\Logics\MenuLogic;

class MenuController extends BaseController
{
    protected $menuLogic;

    public function __construct(MenuLogic $menuLogic)
    {
        $this->menuLogic = $menuLogic;
    }

    /**
     * 菜单树
     * @return mixed
     */
    public function tree(){
        $res = $this->menuLogic->orderBySortTree();
        return $this->respond($res);
    }

    /**
     * 创建菜单
     * @param CreateMenuRequest $request
     * @return mixed
     */
    public function create(CreateMenuRequest $request){
        $res = $this->menuLogic->store($request->validated());
        return $this->respond($res);
    }

    /**
     * 编辑菜单
     * @param UpdateMenuRequest $request
     * @return mixed
     */
    public function update(UpdateMenuRequest $request){
        $res = $this->menuLogic->store($request->validated());
        return $this->respond($res);
    }

    /**
     * 删除菜单
     * @param $id
     * @return mixed
     */
    public function delete($id){
        $res = $this->menuLogic->delete($id);
        return $this->respond($res);
    }
}
